package com.eco
{
	import com.eco.*;
	import com.framework.*;
	
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.utils.*;
	
	//鱼叉
	public class EnemySpear extends Enemy
	{
		public function EnemySpear()
		{
			super( 25, 10, Enemy.ENEMY_SPEAR);
			
			iFreezedFrames = 36;
			iAttackPower = 8;
			iAttackPossibility = 10;
		}
		
		override public function Update():void
		{
			//敌人更新的几个部分
			Move();//执行移动模块
			
			//鱼叉没有摩擦
			//Friction();//执行摩擦模拟模块
			
			switch( iState )
			{
				case Enemy.STATE_IDLE:
				{
					if(  v2dSpeed.getLength() == 0 )
					{
						mcTexture.gotoAndStop("IDLE");
					}
					Attack();
					iState = Enemy.STATE_ATTACK;
					Rotate();//执行自转模块
					break;
				}
				case Enemy.STATE_ATTACK:
				{
					//速度一旦为0就结束攻击，进入闲置状态
					if( v2dSpeed.getLength() == 0 )
					{
						iState = Enemy.STATE_IDLE;
					}
					Rotate();//执行自转模块
					break;
				}
				case Enemy.STATE_DEAD:
				{
					//播放死亡的动画，动画结束后跳转到结束状态
					CreateSoundEvent( CustomEventSound.PLAY_SOUND, SoundInfo.EFF_ENEMY_DIE);
					if( mcTexture.currentFrame == mcTexture.totalFrames )
					{
						trace("EnemyDead");
						iState = Enemy.STATE_END;
					}
					break;
				}
				case Enemy.STATE_END:
				{
					break;
				}
			}
		}
		
		override protected function Attack():void
		{
			if( !ftFighter )
				return;
			
			if( iState == Enemy.STATE_IDLE )
			{
				var dis:MyVector2D = new MyVector2D(ftFighter.x - x, ftFighter.y - y);
				v2dSpeed.plus( dis );
				//v2dSpeed.setLength(iAttackPower )
				v2dSpeed.setLength( Math.min(iAttackPower,v2dSpeed.getLength()-ftFighter.nRadius-this.nRadius+10) );
				mcTexture.gotoAndPlay("ATTACK");
				iState = Enemy.STATE_ATTACK;
			}
		}
		
		override protected function BeatFighter():void
		{
			//玩家被撞直接死亡,鱼叉自己也消亡
			ftFighter.Dead();
			//this.Dead()
			//super.BeatFighter();
		}
		
	}
}